// miniprogram/pages/content/content.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 1,
    title_name: ['请选择您的意向报考省份', '您的性别是？', ' 您的身份是？', '您属于以下哪种情况', '您的学历是？', '您的专业是？'],
    tips: ['军队文职为全国统一考试，可夸省份报考。', '军队文职有近50%的岗位不限性别', '高校毕业生为应届毕业生及毕业两年择业期内未落实工作单位的非应届毕业生。', '军队文职部分岗位面向军队烈士、因公牺牲军人的配偶子女以及现役军人配偶定向招聘，且军队烈士、因公牺牲军人的配偶子女公共科目成绩+10分，现役配偶公共科目考试成绩+5分。', '辅修专业如取得学位证也可以辅修专业报考'],
    province: ['北京', '上海', '山东', '江苏', '浙江', '安徽', '吉林', '福建', '广东', '广西', '海南', '天津', '河北', '山西', '黑龙江', '甘肃', '湖北', '湖南', '河南', '四川', '重庆', '云南', '贵州', '西藏', '宁夏', '新疆', '青海', '陕西', '辽宁', '江西', '内蒙古'],
    sex: ['男', '女', '不限'],
    nature: ['高校毕业生', '社会人才'],
    status: ['军队烈士、因公牺牲军人的配偶子女', '现役军人配偶', '普通公民'],
    edu: ['专科', '本科', '硕士', '博士'],
    page: 53
  },
  provinceChoise: function (e) {
    var that = this;
    that.setData({
      provinceIndex: e.currentTarget.dataset.province
    })
    wx.setStorageSync('province', e.currentTarget.dataset.province)
    setTimeout(function () {
      that.setData({
        index: 2
      })
    }, 500)
  },
  sexChoise: function (e) {
    var that = this;
    that.setData({
      sexIndex: e.currentTarget.dataset.sex
    })
    wx.setStorageSync('sex', e.currentTarget.dataset.sex)
    setTimeout(function () {
      that.setData({
        index: 3
      })
    }, 500)
  },
  natureChoise: function (e) {
    var that = this;
    that.setData({
      natureIndex: e.currentTarget.dataset.nature
    })
    wx.setStorageSync('nature', e.currentTarget.dataset.nature)
    setTimeout(function () {
      that.setData({
        index: 4
      })
    }, 500)
  },
  statusChoise: function (e) {
    var that = this;
    that.setData({
      statusIndex: e.currentTarget.dataset.status
    })
    wx.setStorageSync('status', e.currentTarget.dataset.status)
    setTimeout(function () {
      that.setData({
        index: 5
      })
    }, 500)
  },
  eduChoise: function (e) {
    var that = this;
    that.setData({
      eduIndex: e.currentTarget.dataset.edu
    })
    wx.setStorageSync('edu', e.currentTarget.dataset.edu)
    setTimeout(function () {
      that.setData({
        index: 6
      })
    }, 500)
  },
  zyInput: function (e) {
    this.setData({
      zy: e.detail.value
    })
    wx.setStorageSync('zy', e.detail.value)
    console.log(this.data.zy)
  },
  navto: function (e) {
    var that = this;
    that.setData({
      index: e.currentTarget.dataset.index
    })
  },

  tijiao: function (res) {
    var that = this;
    var phone = wx.getStorageSync('phone');
    var dishi = wx.getStorageSync('province');
    var sex = wx.getStorageSync('sex');
    var nature = wx.getStorageSync('nature');
    var status = wx.getStorageSync('status');
    var edu = wx.getStorageSync('edu');
    var zy = wx.getStorageSync('zy');
    if (phone) {
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/chaxun/writelogs/?actid=44558&callback=?",
        data: {
          phone: phone,
          dishi: dishi,
          sex: sex,
          nature: nature,
          teshu: status,
          edu: edu,
          zy: zy,
        },
      })
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=44558&callback=?",
        data: {
          didian: dishi,
          xl: edu,
          lylb: nature,
          zy: zy,
          limits: '100'
        }, //接收参数
        success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
          if (theJson.status == '2') {
            console.log('暂无数据！')
            wx.showToast({
              title: '暂无数据,可以尝试以专业科目大类搜索',
              icon: 'none',
              duration: 2000
            })
          } else {
            that.setData({
              theList: theJson.lists
            })
            wx.navigateTo({
              url: '../result/result',
            })
          }
          console.log(that.data.theList)
          wx.setStorageSync('result', that.data.theList)

        }
      })
    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        fixed: 1
      })
    }




  },

  getPhoneNumber(e) {
    var that = this;
    var fenxiao = wx.getStorageSync('area');
    var geneal = wx.getStorageSync('agent');
    var page = wx.getStorageSync('page');
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('phone', res.result)
      console.log(res.result)

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 41,
          mobile: res.result,
          areaCode: fenxiao,
          agent: geneal,
          pageId: page
        },
        success: res => {
          console.log(res);
        }
      })

      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=44558&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            fixed: !1
          })
        }
      })
      
      
    }).catch(err => {
      console.error(err);
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})